#include <dbg.h>

#include <cassert>
#include <vector>

using namespace std;

class Solution {
public:
    double findMaxAverage(vector<int>& nums, int k) {
        double sum = 0;

        for (int i = 0; i < k; ++i) {
            sum += nums[i];
        }

        double maxSum = sum;
        for (int i = k; i < nums.size(); ++i) {
            sum = sum + nums[i] - nums[i - k];
            maxSum = max(maxSum, sum);
        }

        return maxSum / k;
    }
};

int main() {
    Solution s;

    vector<int> nums1{1, 12, -5, -6, 50, 3};
    vector<int> nums2{5};
    vector<int> nums3{0, 4, 0, 3, 2};

    assert(s.findMaxAverage(nums1, 4) == 12.75);
    assert(s.findMaxAverage(nums2, 1) == 5.0);
    assert(s.findMaxAverage(nums3, 1) == 4.0);

    return 0;
}